package stu.day25_day32.day28;

import java.util.ArrayList;
import java.util.List;

public class hw2 {
    public List<List<Integer>> subsets(int[] nums) {

        List<List<Integer>> list = new ArrayList<>();
        List<Integer> arr = new ArrayList<>();

        tee(nums,list,arr,0);

        return list;

    }


    public void dfs(int[] nums,List<List<Integer>> list,List<Integer> arr,int index){


        if(index==nums.length){
            list.add(new ArrayList<>(arr));
            return;
        }
        arr.add(nums[index]);
        dfs(nums,list,arr,index+1);

        arr.removeLast();
        dfs(nums, list, arr, index + 1);


    }

    public void tee(int[] nums,List<List<Integer>> list,List<Integer> arr,int index){
        list.add(new ArrayList<Integer>(arr));
        for(int i=index;i<nums.length;i++){
            if(i>index && nums[i]==nums[i-1]){
                continue;
            }

            arr.add(nums[i]);
            tee(nums,list,arr,i+1);
            arr.remove(arr.size()-1);
        }

    }


}
